package com.infolab.aims.domain.asset;

import java.io.Serializable;

import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;

import com.infolab.aims.common.SpecialMuLineToStringStyle;
import com.infolab.aims.common.bean.AbstractModelBean;
import com.infolab.aims.domain.Location;

@Entity
@Table(name="AMTB_ASSET_TRANSACTION_ITEM")
public class AssetTransactionItem extends AbstractModelBean implements Serializable {
	
	@EmbeddedId
	private AssetTransactionItemPK assetTransactionItemPK;
	
	@ManyToOne
	@JoinColumn(name="assetModelId")
	private AssetModel assetModel;
	
	private Float assetPrice;
	
	private String serialNo;
	
	private String assetTag;
	
	private Integer assetTransactionQuantity;
	
	private String assetTransactionStatus;
	
	private String remarks;
	
	@ManyToOne
	@JoinColumn(name="locationId")
	private Location location;
	
	@Transient
	private boolean deleted;
	
	private String companyCode;
	
	public String getAuditContentHead()
	{
		AssetModel model = assetModel;
		if(assetModel==null){
			return "Empty Asset Model";
		}
		
		if(StringUtils.equals(assetModel.getAssetType(), AssetModel.ASSETTYPE_EQUIPMENT)){
			return new ToStringBuilder(this,SpecialMuLineToStringStyle.SPECIAL_MULINE_STYLE)
			.append("Asset Model", model.getAssetModelCode() + " " + model.getAssetModelName())
			.append("Serial No", serialNo)
			.append("Remarks", remarks)
			.toString();
		}else{
			return new ToStringBuilder(this,SpecialMuLineToStringStyle.SPECIAL_MULINE_STYLE)
			.append("Asset Model", model.getAssetModelCode() + " " + model.getAssetModelName())
			.append("Qty", assetTransactionQuantity)
			.append("Remarks", remarks)
			.toString();
		}
		
	}
	
	public String getAuditContentHeadForInitialBalance()
	{
		if( assetModel!=null) {
		
			if(StringUtils.equals(assetModel.getAssetType(), AssetModel.ASSETTYPE_EQUIPMENT)){
				return new ToStringBuilder(this,SpecialMuLineToStringStyle.SPECIAL_MULINE_STYLE)
				.append("Company Code", companyCode)
				.append("Location", location.getLocationCode()+" "+location.getLocationName())
				.append("Serial No", serialNo)
				.toString();
			}else{
									
					return new ToStringBuilder(this,SpecialMuLineToStringStyle.SPECIAL_MULINE_STYLE)
					.append("Company Code", companyCode)
					.append("Location", location.getLocationCode()+" "+location.getLocationName())			
					.append("Initial Balance Qty", assetTransactionQuantity)
					.toString();
				
			}
		}
		return "N/A";
		
	}

	public AssetTransactionItemPK getAssetTransactionItemPK() {
		return assetTransactionItemPK;
	}

	public void setAssetTransactionItemPK(
			AssetTransactionItemPK assetTransactionItemPK) {
		this.assetTransactionItemPK = assetTransactionItemPK;
	}

	public AssetModel getAssetModel() {
		return assetModel;
	}

	public void setAssetModel(AssetModel assetModel) {
		this.assetModel = assetModel;
	}

	public Float getAssetPrice() {
		return assetPrice;
	}

	public void setAssetPrice(Float assetPrice) {
		this.assetPrice = assetPrice;
	}

	public String getSerialNo() {
		return serialNo;
	}

	public void setSerialNo(String serialNo) {
		this.serialNo = serialNo;
	}

	public Integer getAssetTransactionQuantity() {
		return assetTransactionQuantity;
	}

	public void setAssetTransactionQuantity(Integer assetTransactionQuantity) {
		this.assetTransactionQuantity = assetTransactionQuantity;
	}

	public String getAssetTransactionStatus() {
		return assetTransactionStatus;
	}

	public void setAssetTransactionStatus(String assetTransactionStatus) {
		this.assetTransactionStatus = assetTransactionStatus;
	}

	public Location getLocation() {
		return location;
	}

	public void setLocation(Location location) {
		this.location = location;
	}

	public String getAssetTag() {
		return assetTag;
	}

	public void setAssetTag(String assetTag) {
		this.assetTag = assetTag;
	}

	public String getRemarks() {
		return remarks;
	}

	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}
	
	public boolean isApproved()
	{
		return StringUtils.equalsIgnoreCase(assetTransactionStatus, AssetTransaction.TRANSACTIONSTATUS_APPROVED);
	}

	public boolean isDeleted() {
		return deleted;
	}

	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}

	public String getCompanyCode() {
		return companyCode;
	}

	public void setCompanyCode(String companyCode) {
		this.companyCode = companyCode;
	}
	
}
